package com.shxzz.shortlink.admin.config;

import com.shxzz.shortlink.admin.common.biz.user.LoginAuthInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * @author shxzz
 * @create 2023-12-12-21:06
 * @description WebMvcConfiguration 配置类
 */
@Configuration
@RequiredArgsConstructor
public class MyWebMvcConfiguration implements WebMvcConfigurer {

    private final LoginAuthInterceptor loginAuthInterceptor;
    private final List<String> whiteList = Arrays.asList(
            "/api/short-link/admin/v1/user/has-username",
            "/api/short-link/admin/v1/user/login",
            "/api/short-link/admin/v1/user/register"
    );

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginAuthInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(whiteList);
    }
}
